package com.shimao.celnet.payment.service.impl;

import com.github.pagehelper.PageHelper;
import com.shimao.celnet.payment.form.BCityForm;
import com.shimao.celnet.payment.model.BCity;
import com.shimao.celnet.payment.service.BCityService;
import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.StringUtil;

import java.util.List;


/**
 * 城市管理
 * Created by ensure on 2017/12/3.
 */
@Service
public class BCityServiceImpl extends BaseServiceImpl<BCity> implements BCityService {
    protected Logger logger = Logger.getLogger(this.getClass());

    /**
     * 分页查询
     * @param formBean
     * @param pageNum
     * @param length
     * @return
     */
    @Override
    public BCityForm getByPage(BCityForm formBean, int pageNum, int length) {
        logger.info("分页查询--开始");
        //分页查询
        Example example = new Example(BCity.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(formBean.getCityName())) {
            //参数名称
            criteria.andLike("cityName", "%" + formBean.getCityName() + "%");
        }


        //分页查询
        PageHelper.startPage(pageNum, length);
        List<BCity> tableList = getByExample(example);
        formBean.setPageInfo(tableList);
        return  formBean;
    }

    /**
     *新增保存
     * @return
     */
    @Override
    public int save(BCity sBean){
        int retCnt=0;
        String loginUserGuid = (String) SecurityUtils.getSubject().getSession().getAttribute("userSessionId");
        sBean.setUpdateUserGuid(loginUserGuid);
        sBean.setCreatedUserGuid(loginUserGuid);
        sBean.setGuid(getGuid());//guid
        retCnt = super.save(sBean);

        return retCnt;
    }

    /**
     *修改保存
     * @return
     */
    @Override
    public int update(BCity sBean){
        String loginUserGuid = (String) SecurityUtils.getSubject().getSession().getAttribute("userSessionId");
        sBean.setUpdateUserGuid(loginUserGuid);
        int retCnt = super.update(sBean);

        return retCnt;
    }

}
